<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:pe="http://primefaces.org/ui/extensions">

    <h:body>

        <ui:composition template="/resources/template/template.xhtml">

            <ui:define name="content">
                <h:form>
                    <p:panel header="OPD Payment Discount Matrix" id="reportPrint">

                        <p:panel header="Add new Matrix" >
                            <p:panelGrid columns="2" >
                                <h:outputLabel value="Discount Scheme"/>
                                <p:autoComplete forceSelection="true" 
                                                value="#{opdMemberShipDiscountController.paymentScheme}" 
                                                completeMethod="#{paymentSchemeController.completePaymentScheme}" 
                                                var="mem" itemLabel="#{mem.name}" itemValue="#{mem}" >
                                </p:autoComplete>
                                <h:outputLabel value="Department :" />
                                <p:autoComplete value="#{opdMemberShipDiscountController.department}" 
                                                forceSelection="true"
                                                completeMethod="#{departmentController.completeDept}" 
                                                var="dep" itemLabel="#{dep.name}" itemValue="#{dep}" >
                                    <p:column>
                                        <h:outputLabel value="#{dep.name}"/>
                                    </p:column>
                                    <p:column>
                                        <h:outputLabel value="#{dep.institution.name}"/>
                                    </p:column>
                                </p:autoComplete>
                                <h:outputLabel value="Payment Method"/>
                                <p:selectOneMenu   value="#{opdMemberShipDiscountController.paymentMethod}"  >
                                    <f:selectItem itemLabel="Select" />                           
                                    <f:selectItems value="#{enumController.paymentMethods}" />                                    
                                </p:selectOneMenu>
                                <h:outputLabel value="Discount" ></h:outputLabel>
                                <p:inputText autocomplete="off" value="#{opdMemberShipDiscountController.margin}" />
                                <h:outputLabel value="" />
                                <p:commandButton id="btnAdd" value="Add" ajax="false" 
                                                action="#{opdMemberShipDiscountController.saveSelectedDepartmentPaymentScheme}" />

                                <p:defaultCommand target="btnAdd"/>
                            </p:panelGrid>
                            <p:commandButton ajax="false" value="Excel" styleClass="noPrintButton" style="float: right;" >
                                <pe:exporter type="xlsx" target="inwd" fileName="Price_metrix_investigation"  />
                            </p:commandButton>
                            <p:commandButton ajax="false" value="Fill" 
                                            action="#{opdMemberShipDiscountController.createItemsDepartmentsPaymentScheme}" />
                            <p:commandButton ajax="false" value="Print" styleClass="noPrintButton" >                                         
                                <p:printer target="reportPrint"/>
                            </p:commandButton>

                        </p:panel>

                        <p:panel header="Price Matrix" >

                            <p:dataTable id="inwd" value="#{opdMemberShipDiscountController.items}"
                                         filteredValue="#{opdMemberShipDiscountController.filterItems}"
                                         var="a" editable="true" scrollable="true" scrollHeight="500">
                                <p:column headerText="Discount Scheme">
                                    <p:autoComplete forceSelection="true" 
                                                    value="#{a.paymentScheme}" 
                                                    completeMethod="#{paymentSchemeController.completePaymentScheme}" 
                                                    var="mem" itemLabel="#{mem.name}" itemValue="#{mem}" >
                                    </p:autoComplete>
                                </p:column>

                                <p:column headerText="Department Name" 
                                          filterBy="#{a.department.name}" filterMatchMode="contains">
                                    <p:autoComplete forceSelection="true" value="#{a.department}" 
                                                    completeMethod="#{departmentController.completeDept}" 
                                                    var="dep" itemLabel="#{dep.name}" itemValue="#{dep}" >
                                        <p:column>
                                            <h:outputLabel value="#{dep.name}"/>
                                        </p:column>
                                        <p:column>
                                            <h:outputLabel value="#{dep.institution.name}"/>
                                        </p:column>
                                    </p:autoComplete>

                                </p:column>

                                <p:column headerText="Payment Method">
                                    <p:selectOneMenu  value="#{a.paymentMethod}"  >
                                        <f:selectItem itemLabel="Select" />                           
                                        <f:selectItems value="#{enumController.paymentMethods}" />                                    
                                    </p:selectOneMenu>
                                </p:column>
                                <p:column  headerText="Discount Percent">
                                    <h:inputText autocomplete="off" value="#{a.discountPercent}" >
                                        <f:convertNumber pattern="#,##0.00"/>
                                    </h:inputText>
                                </p:column>
                                <p:column>
                                    <p:commandButton ajax="false" value="Update" 
                                                    action="#{opdMemberShipDiscountController.onEdit(a)}"/> 
                                </p:column>
                                <p:column>
                                    <p:commandButton ajax="false" value="Delete" action="#{opdMemberShipDiscountController.deleteDepartmentPaymentScheme()}">
                                        <f:setPropertyActionListener value="#{a}" target="#{opdMemberShipDiscountController.current}"/>
                                    </p:commandButton>
                                </p:column>

                            </p:dataTable>


                        </p:panel>

                    </p:panel>

                </h:form>
            </ui:define>


        </ui:composition>

    </h:body>
</html>
